package com.sx.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import com.dfec.utils.DruidPlugin;
import com.dfec.utils.StringUtils;
import com.dfec.utils.ToolDateTime;

public class ServeProductService {
//	两种连接池切换
//	QueryRunner qr=new QueryRunner(DataSourceUtils.getDatasSource());
	QueryRunner qr=new QueryRunner(DruidPlugin.getDataSource());
	List<Object> list=null;
	public List<Object> getProduct(String position,String first_class,String second_class,int page,int size,String keyWord) throws Exception{
		list=new ArrayList<>();
		int num=((page-1)*size);
		StringBuilder sb=new StringBuilder();
		  sb.append("SELECT id ,title,file_path,product_type,up_time")
		  .append(" FROM d_server_ptoduct WHERE position LIKE'%"+position+"%' AND first_class='"+first_class+"' AND second_class='"+second_class+"'");
		  if(StringUtils.isNotBlank(keyWord))sb.append(" and title like'%"+keyWord+"%'");
		  sb.append("order by up_time desc LIMIT "+num+","+size);
		  //		System.out.println(sb.toString());
		List<Map<String, Object>> result = qr.query(sb.toString(), new MapListHandler());
		list.add(result);
		return list;
	}
	
	public List<Object> getProductDiteals(String id) throws Exception{
		list=new ArrayList<>();
		StringBuilder sb=new StringBuilder();
		 sb.append("SELECT * FROM d_server_ptoduct WHERE id="+id);
//		System.out.println(sb.toString());
		List<Map<String, Object>> result = qr.query(sb.toString(), new MapListHandler());
		list.add(result);
		return list;
	}
	
	
	
}
